package com.rf.page;

import java.util.List;

/**
 * @Description
 * @Author rf
 * @Date 2022/4/2
 */
public class PageBean<T> {

    private int pageNow = 1; //当前页  用户输入
    private int pageCount = 5; //每页显示多少条记录  用户输入  预定义
    private int totalRows; // 总记录数   查询得到
    private int totalPages; //总页数   计算 totalRows和pageCount计算得到
    private int start; //每页查询开始下标   计算 pageNow和pageCount
    private List<T> data; //查询

    public PageBean() {
    }

    public PageBean(int pageNow, int pageCount) {
        this.pageNow = pageNow;
        this.pageCount = pageCount;
    }

    public int getPageNow() {
        return pageNow;
    }

    public void setPageNow(int pageNow) {
        this.pageNow = pageNow;
    }

    public int getPageCount() {
        return pageCount;
    }

    public void setPageCount(int pageCount) {
        this.pageCount = pageCount;
    }

    public int getTotalRows() {
        return totalRows;
    }

    public void setTotalRows(int totalRows) {
        this.totalRows = totalRows;
    }

    public int getTotalPages() {
        //计算 totalRows和pageCount计算得到   15/5  3    16/5  3+1
        return totalRows%pageCount==0?totalRows/pageCount:totalRows/pageCount+1;
    }

    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }

    public int getStart() {
        /*
        计算   pageNow   pageCount    start
                 1          5          0
                 2          5          5
                 3          5          10
         */

        return (pageNow-1)*pageCount;
    }

    public void setStart(int start) {
        this.start = start;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "PageBean{" +
                "pageNow=" + pageNow +
                ", pageCount=" + pageCount +
                ", totalRows=" + totalRows +
                ", totalPages=" + getTotalPages() +
                ", start=" + getStart() +
                ", data=" + data +
                '}';
    }
}
